package com.hcrazy.manchester.app.services;

import java.util.List;

import org.joda.time.DateTime;

import com.hcrazy.manchester.app.jdbc.RadioProgramDAO;
import com.hcrazy.manchester.app.pojo.PageModel;
import com.hcrazy.manchester.app.pojo.RadioProgram;

public class RadioProgramService {

	private RadioProgramDAO programDAO;

	public RadioProgramDAO getProgramDAO() {
		return programDAO;
	}

	public void setProgramDAO(RadioProgramDAO programDAO) {
		this.programDAO = programDAO;
	}
	
	public void addOrUpdateProgram(RadioProgram program) throws Exception{
		if(null == program){
			return;
		}
		program.setCreateDate(new DateTime().toString("yyyy-MM-dd HH:mm:ss"));
		if(program.getProgramId() > 0){
			programDAO.updateRadioProgram(program);
		}else{
			programDAO.addRadioProgram(program);
		}
	}
	
	public void addRadioProgram(RadioProgram program) throws Exception{
		programDAO.addRadioProgram(program);
	}
	
	public void updateRadioProgram(RadioProgram program) throws Exception{
		programDAO.updateRadioProgram(program);
	}
	
	public List<RadioProgram> listAllInfos() throws Exception{
		return programDAO.listAllInfos();
	}
	
	public List<RadioProgram> getAllInfosByChannelId(int channelId,boolean hasDetail) throws Exception{
		return programDAO.getAllInfosByChannelId(channelId, hasDetail);
	}
	
	public PageModel getPagedInfos(PageModel model,String search,int channelId,int fromType) throws Exception{
		return programDAO.getPagedInfos(model, search, channelId, fromType);
	}
	
	public RadioProgram getById(int programId) throws Exception{
		return programDAO.getById(programId);
	}
	
	public RadioProgram getById(int programId,boolean hasDetail) throws Exception{
		return programDAO.getById(programId, hasDetail);
	}
	
	public void delRadioProgram(int programId) throws Exception{
		programDAO.delRadioProgram(programId);
	}
	
}
